package com.huike.web.controller.business;

import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.dto.TbBusinessPageDTO;
import com.huike.business.domain.vo.TbBusinessVO;
import com.huike.business.service.TbBusinessService;
import com.huike.clues.domain.vo.AssignmentVo;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商机Controller
 * @date 2023-04-25
 */
@Api(tags = "商机相关接口")
@RestController
@RequestMapping("/business")
@Slf4j
@RequiredArgsConstructor
public class TbBusinessController {
    private final TbBusinessService tbBusinessService;


    /**
     * 新增商机接口
     * @param tbBusiness
     * @return
     */
    @ApiOperation("新增商机接口")
    @PostMapping()
    public AjaxResult add(@RequestBody TbBusiness tbBusiness){
        log.info("新增商机接口：{}",tbBusiness);
        tbBusinessService.add(tbBusiness);
        return AjaxResult.success();
    }

    /**
     * 修改商机接口
     * @param tbBusinessVO
     * @return
     */
    @ApiOperation("修改商机接口")
    @PutMapping()
    public AjaxResult upadte(@RequestBody TbBusinessVO tbBusinessVO){
        log.info("修改商机接口：{}",tbBusinessVO);
        tbBusinessService.updateBusiness(tbBusinessVO);
        return AjaxResult.success();
    }

    /**
     * 踢回公海接口
     * @param id
     * @param reason
     * @return
     */
    @ApiOperation("踢回公海接口")
    @PutMapping("/back/{id}/{reason}")
    public AjaxResult back(@PathVariable Long id,@PathVariable String reason){
        log.info("踢回公海接口:{},{}",id,reason);
        tbBusinessService.back(id,reason);
        return AjaxResult.success();
    }

    /**
     * 批量捞取接口
     * @param assignmentVo
     * @return
     */
    @ApiOperation("批量捞取接口")
    @PutMapping("/gain")
    public AjaxResult gain(@RequestBody AssignmentVo assignmentVo){
        log.info("批量捞取接口:{}",assignmentVo);
        tbBusinessService.gain(assignmentVo);
        return AjaxResult.success();
    }

    /**
     * 查询公海池接口
     * @param tbBusinessPageDTO
     * @return
     */
    @ApiOperation("查询公海池接口")
    @GetMapping("/pool")
    public TableDataInfo<List<TbBusinessVO>> poolList(TbBusinessPageDTO tbBusinessPageDTO){
        log.info("查询公海池接口:{}",tbBusinessPageDTO);
        TableDataInfo<List<TbBusinessVO>> tableDataInfo = tbBusinessService.poolList(tbBusinessPageDTO);
        return tableDataInfo;
    }

    /**
     * 删除商机接口
     * @param ids
     * @return
     */
    @ApiOperation("删除商机接口")
    @DeleteMapping("/{ids}")
    public AjaxResult delete(@PathVariable List<Long> ids ){
        log.info("删除商机接口:{}",ids);
        tbBusinessService.delete(ids);
        return AjaxResult.success();
    }


    /**
     * 商机分配接口-------------------------------------------------------------------
     * @param assignmentVo
     * @return
     */
    @ApiOperation("商机分配接口")
    @PutMapping("/assignment")
    public AjaxResult assignment(@RequestBody AssignmentVo assignmentVo){
        log.info("商机分配接口：{}",assignmentVo);
        tbBusinessService.assignment(assignmentVo);
        return AjaxResult.success("操作成功！");
    }

    /**
     * 获取商机详细信息接口
     * @param id
     * @return
     */
    @ApiOperation("获取商机详细信息接口")
    @GetMapping("/{id}")
    public AjaxResult<TbBusinessVO> findById(@PathVariable Long id){
        log.info("获取商机详细信息接口:{}",id);
        TbBusinessVO tbBusinessVO = tbBusinessService.findById(id);
        return AjaxResult.success(tbBusinessVO);
    }

    /**
     * 查询商机列表接口
     * @param tbBusinessPageDTO
     * @return
     */
    @ApiOperation("查询商机列表接口")
    @GetMapping("/list")
    public TableDataInfo<List<TbBusinessVO>> pageList(TbBusinessPageDTO tbBusinessPageDTO){
        log.info("查询商机列表接口:{}",tbBusinessPageDTO);
        TableDataInfo<List<TbBusinessVO>> tableDataInfo = tbBusinessService.pageList(tbBusinessPageDTO);
        return tableDataInfo;
    }
}
